<?php

/**
 * RP System
 *
 * @version 1.0
 * @copyright 2004 Ron Planken
 */

class player_attribute {


	function get($player_id = 0){

		global $dbh;

		if ($player_id == 0) {
			$query ='SELECT   player_id
			                 ,attribute_id
							 ,id
			                 ,value
						FROM player_attributes
					GROUP BY player_id, attribute_id;
							';
		} else {
			$query = "SELECT  pa.player_id
			                 ,attribute_id
							 ,id
			                 ,value
						FROM player_attributes pa
						JOIN player p ON p.player_id = pa.player_id
					   WHERE p.user_id = $player_id
					GROUP BY pa.player_id, attribute_id;
							";
			}

		$player_attributes = SelectMultiRpQuery($query, $dbh);

		return $player_attributes;

	}



/*
							,c.category_short_name
						    ,c.category_long_name
						    ,c.category_image

						    JOIN raid_points_category c ON c.category_id = r.category_id*/

	function get_category($attribute_id = 0){

		global $dbh;

		if ($attribute_id == 0) {
			$query ='SELECT  id
			                 ,name
			                 ,short_name
			                 ,description
			                 ,type
			                 ,picture_link
						FROM attribute
					ORDER BY id;
							';
		} else {
			$query = "SELECT  id
			                 ,name
			                 ,short_name
			                 ,description
			                 ,type
			                 ,picture_li
					   WHERE id = $attribute_id;
							";
		}

		$categories = SelectMultiQuery($query, $dbh);

		return $categories;

	}

	function save($id, $attribute_id, $player_id, $value) {

		global $dbh;

		$id = secure_int($id);
		$attribute_id = secure_int($attribute_id);
		$player_id =  secure_int($player_id);
		$value = secure_string($value);

		if ($id == 0) {
			$query ="INSERT INTO player_attributes
						   (id
			               ,attribute_id
			               ,player_id
			               ,value
						   )
					VALUES ($id
			               ,$attribute_id
			               ,$player_id
			               ,$value
						   )
							";
			$status = InsertQuery($query, $dbh);

		} else {
			$query ="UPDATE player_attributes
						SET attribute_id = $attribute_id
			               ,player_id = $player_id
			               ,value = $value
					  WHERE id = $id
							";
			$status = UpdateQuery($query, $dbh);
		}
		
		global $debug;
		
		$debug->log_action($query);
		
		return $status;

	}
}
?>